package com.flot.yazb.widget;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.StyleRes;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.flot.yazb.R;
import com.flot.yazb.base.BDialog;
import com.flot.yazb.widget.wheel.WheelView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class WheelDialog extends BDialog {

    private  int sel;
    private  List<String> arr;
    @BindView(R.id.main_wv)
    WheelView wva;
    @BindView(R.id.save)
    Button save;

    private String selectEdText;
    private int selectItem;

    public WheelDialog(Context context) {
        super(context);
    }
    public WheelDialog(Context context, List<String> arrs, int po) {
        super(context);
        this.arr=arrs;
        this.sel=po;
        selectItem=po;
        selectEdText=arrs.get(po);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_whell);
        ButterKnife.bind(this);
        wva.setOffset(2);
        wva.setItems(arr);
        wva.setSeletion(sel);
        wva.setOnWheelViewListener(new WheelView.OnWheelViewListener() {
            @Override
            public void onSelected(int selectedIndex, String item) {
                Log.d("setOnWheelViewListener", "onSelected: " + selectedIndex + ", item: " + item);
                selectEdText = item;
                selectItem = selectedIndex;
            }
        });
        save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) {
                    mListener.getSelected(selectEdText);
                    mListener.getPosition(selectItem);
                    dismiss();
                }
            }
        });
    }

    @Override
    public boolean isCancelable(boolean b) {
        return false;
    }

    @Override
    public int setGravity(int gravity) {
        return 0;
    }

    @Override
    public int setPadWidth(float width) {
        return 0;
    }

    @Override
    public int setPadHeight(float height) {
        return 0;
    }


    public selectedEnd mListener;

    public interface selectedEnd {
        void getSelected(String text);

        void getPosition(int position);
    }

    public void setOnSelectedListener(selectedEnd listener) {
        mListener = listener;
    }

}
